package com.mini.repository;

import com.mini.model.BusinessTraditionChance;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

/**
 * @author shixiaopeng  on 2020/12/2
 */
@Repository
public interface BusinessTraditionChanceRepository extends JpaRepository<BusinessTraditionChance, Long>, JpaSpecificationExecutor<BusinessTraditionChance> {

    List<BusinessTraditionChance> findAllByIdIn(List<Long> ids);

    List<BusinessTraditionChance> findAllByTodayCallNumGreaterThan(Integer num);

    List<BusinessTraditionChance> findAllByTodayChatNumGreaterThan(Integer num);


    @Transactional
    @Modifying
    @Query(value = "update business_tradition_chance p set p.today_call_num = 0 where p.today_call_num > 0", nativeQuery = true)
    void updateTodayCallNum();

    @Transactional
    @Modifying
    @Query(value = "update business_tradition_chance p set p.today_chat_num = 0 where p.today_chat_num > 0", nativeQuery = true)
    void updateTodayChatNum();
}
